<template>
  <div class="contents">
    <div class="rankingModule">
      <el-row type="flex" align="middle">
        <el-col :span="4">
          <span class="_icons"></span>
          <span>司机绩效排名</span>
        </el-col>
        <el-col :span="18">
          <div style="display: flex; align-items: center;">
            发货日期:
            <el-radio-group
              v-model="radio1"
              size="small"
              style="margin: 0 15px;"
            >
              <el-radio-button label="昨日"></el-radio-button>
              <el-radio-button label="近7日"></el-radio-button>
              <el-radio-button label="近30天"></el-radio-button>
            </el-radio-group>
            <el-date-picker
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              style="width: 200px;"
            ></el-date-picker>
          </div>
        </el-col>
        <el-col :span="13">
          <el-radio-group v-model="radio2" size="small">
            <el-radio-button label="按配送金额"></el-radio-button>
            <el-radio-button label="按配送订单数"></el-radio-button>
            <el-radio-button label="按发货数"></el-radio-button>
          </el-radio-group>
        </el-col>
      </el-row>
      <!-- 图表 -->
      <vab-chart
        style="width: 100%;"
        :init-options="initOptions"
        :option="option"
        theme="vab-echarts-theme"
      />
    </div>
    <div class="divider"></div>
    <div style="margin-top: 20px; padding: 0px 20px 10px;">
      <el-form :inline="true">
        <el-form-item label="搜索:">
          <el-input placeholder="输入司机名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary">查询</el-button>
          <el-dropdown style="margin-left: 10px;">
            <el-button>
              导出
              <i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>按司机导出</el-dropdown-item>
              <el-dropdown-item>按一级分类导出</el-dropdown-item>
              <el-dropdown-item>配送详情导出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-form-item>
      </el-form>
      <el-table :data="table1" style="width: 100%; margin-top: 10px;">
        <el-table-column type="index" width="50" label="序号"></el-table-column>
        <el-table-column label="司机名称"></el-table-column>
        <el-table-column sortable label="配送订单数"></el-table-column>
        <el-table-column sortable label="配送金额"></el-table-column>
        <el-table-column label="出车天数"></el-table-column>
        <el-table-column label="发货数量"></el-table-column>
        <el-table-column label="包裹数"></el-table-column>
        <el-table-column label="工资"></el-table-column>
        <el-table-column label="操作"></el-table-column>
      </el-table>
      <el-pagination
        background
        layout="total, prev, pager, next,sizes"
        :page-size="10"
        :page-sizes="[20, 30, 40, 50]"
        style="text-align: right;"
        :total="0"
      />
    </div>
  </div>
</template>

<script>
  import VabChart from '@/extra/VabChart'
  export default {
    components: {
      VabChart,
    },
    data() {
      return {
        radio1: '近30天',
        radio2: '按配送金额',
        initOptions: {
          renderer: 'svg',
        },
        option: {
          tooltip: {
            trigger: 'axis',
            extraCssText: 'z-index:1',
          },
          grid: {
            top: '5%',
            left: '2%',
            right: '4%',
            bottom: '0%',
            containLabel: true,
          },
          xAxis: [
            {
              type: 'category',
              boundaryGap: false,
              data: [],
              axisTick: {
                alignWithLabel: true,
              },
            },
          ],
          yAxis: [
            {
              type: 'value',
            },
          ],
          series: [
            {
              name: '访问量',
              type: 'line',
              data: [],
              smooth: true,
              areaStyle: {},
              itemStyle: {
                borderRadius: [0, 5, 5, 0],
                color: new VabChart.graphic.LinearGradient(
                  0,
                  0,
                  1,
                  0,
                  ['#3ED572', '#399efd'].map((color, offset) => ({
                    color,
                    offset,
                  }))
                ),
              },
            },
          ],
        },
        table1: [],
      }
    },
    mounted() {
      const base = +new Date(2020, 1, 1)
      const oneDay = 24 * 3600 * 1000
      const date = []

      const data = [Math.random() * 1500]
      let now = new Date(base)

      const addData = (shift) => {
        now = [now.getFullYear(), now.getMonth() + 1, now.getDate()].join('/')
        date.push(now)
        data.push(_.random(20000, 60000))

        if (shift) {
          date.shift()
          data.shift()
        }

        now = new Date(+new Date(now) + oneDay)
      }

      for (let i = 1; i < 6; i++) {
        addData()
      }
      addData(true)
      this.option.xAxis[0].data = date
      this.option.series[0].data = data
      this.timer = setInterval(() => {
        addData(true)
        this.option.xAxis[0].data = date
        this.option.series[0].data = data
      }, 6000)
    },
  }
</script>

<style lang="scss" scoped>
  .contents {
    padding: 10px 20px;

    .rankingModule {
      margin: 10px 0 40px;

      ._icons {
        display: inline-block;
        width: 3px;
        height: 12px;
        background: #333;
        margin-right: 5px;
      }
    }

    .divider {
      height: 16px;
      background: #f2f3f5;
      width: 100%;
    }
  }
</style>
